
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
class InputView extends StatefulWidget {

  final String labelText;
        String errorText;
  final TextInputType keyboardType;///键盘类型
  final TextEditingController textEditingController;///获取值
  final TextEditingController otherTextEditingController;///获取另一个值
  final bool obscureText;///是否隐藏
  final FocusNode focusNode;///焦点
 final List<TextInputFormatter> inputFormatters;//输入限制
  ///
   InputView({
    Key key,
    this.labelText,
    this.keyboardType,
    this.textEditingController,
    this.errorText,
    this.focusNode,
    this.otherTextEditingController,
    this.obscureText = false,
     this.inputFormatters
  }) : super(key: key);

  @override
  _InputViewState createState() => _InputViewState();

}
class _InputViewState extends State<InputView> {

  bool _isShowErrorLable;///是否显示 错误提示

  @override
  Widget build(BuildContext context) {
    return TextField(
      obscureText: widget.obscureText,
      controller: widget.textEditingController,
      keyboardType: widget.keyboardType,
      focusNode: widget.focusNode,
      inputFormatters: widget.inputFormatters,
      decoration: InputDecoration(
          labelText: widget.labelText,
          labelStyle: new TextStyle(color: Colors.white54),
          hintStyle: new TextStyle(color: Colors.white70),
          enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(
              color: Colors.white30,
              width: 0.5,
            ),
          ),
          focusedBorder: UnderlineInputBorder(
              borderSide: BorderSide(
                color: Colors.white,
                width: 0.5,
              )),
          errorText:  widget.errorText,
      ),
      style: new TextStyle(color: SQColor.white),
      cursorColor: SQColor.white,
      onChanged: (String str) {

        print("这是什么$str");
        if(widget.labelText == "手机号码") {

          RegExp exp = RegExp('^^(1[3-9])\\d{9}\$');
          bool matched = exp.hasMatch(str);
          if (str != null && str.length == 11 && matched) {

            setState(() {
              widget.errorText = null;
            });

          } else {
           setState(() {
             widget.errorText = "请输入正确格式的手机号";
           });
          }

        }else if (widget.labelText == "确认密码"||widget.labelText == "设置密码") {
          if(str !=widget.otherTextEditingController.text) {
            setState(() {
              widget.errorText = "您两次输入的密码不一致";
            });
          }else {
            setState(() {
              widget.errorText = null;
            });
          }
        }
      },
    );
  }
}
